package com.bw.z.mvp.view.user.adapter;

import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.bw.z.R;
import com.bw.z.mvp.model.entity.UserItemEntity;
import com.bw.z.mvp.view.activity.MoreSetActivity;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import org.jetbrains.annotations.NotNull;

public class UserAdapter extends BaseQuickAdapter<UserItemEntity, BaseViewHolder> {

    public UserAdapter() {
        super(R.layout.view_user_items);
    }

    @Override
    protected void convert(@NotNull BaseViewHolder baseViewHolder, UserItemEntity userItemEntity) {
        baseViewHolder.setText(R.id.mine_item_tv, userItemEntity.name);

        ImageView mine_item_img = baseViewHolder.findView(R.id.mine_item_img);
        LinearLayout mine_item_linear = baseViewHolder.findView(R.id.mine_item_linear);

        mine_item_img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                userItemEntity.selFlag = !userItemEntity.selFlag;
                if (userItemEntity.name.equals("夜间模式")) {
                    if (userItemEntity.selFlag) {
                        baseViewHolder.setImageResource(R.id.mine_item_img, R.mipmap.new_on);
                    } else {
                        baseViewHolder.setImageResource(R.id.mine_item_img, R.mipmap.new_off);
                    }
                }
            }
        });

        if (userItemEntity.name.equals("夜间模式")) {
            baseViewHolder.setImageResource(R.id.mine_item_img, R.mipmap.new_off);
        } else {
            baseViewHolder.setImageResource(R.id.mine_item_img, R.mipmap.res_7icon_306);
        }

        if (userItemEntity.name.equals("更多设置")) {
            mine_item_linear.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    getContext().startActivity(new Intent(v.getContext(), MoreSetActivity.class));
                }
            });
        }
    }
}
